package com.leet.everyday;

import java.util.Comparator;
import java.util.PriorityQueue;

public class SmallestK {
    public int[] smallestK(int[] arr, int k) {
        PriorityQueue<Integer> p = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });
        for(int i = 0;i < arr.length;i++){
            p.add(arr[i]);
        }
        int[] ans = new int[k];
        int i = 0;
        while(k!=0){
            k--;
            ans[i++] = p.poll();
        }
        return ans;
    }


}
